home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / libc / bzero.c < prev    next >
C/C++ Source or Header  |  1991-03-24  |  3KB  |  112 lines

  1. /* 
  2.  * bzero.c --
  3.  *
  4.  *    Source code for the "bzero" library routine.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/bstring/RCS/bzero.c,v 1.6 91/03/24 19:03:13 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. /*
  21.  * The following mask is used to detect proper alignment of addresses
  22.  * for doing word operations instead of byte operations.  It is
  23.  * machine-dependent.  If none of the following bits are set in an
  24.  * address, then word-based operations may be used. This value is imported
  25.  * from machparam.h
  26.  */
  27.  
  28. #include "machparam.h"
  29.  
  30. #define WORDMASK WORD_ALIGN_MASK
  31.  
  32. #ifdef KERNEL
  33. #include <vmHack.h>
  34. #endif
  35.  
  36. /*
  37.  *----------------------------------------------------------------------
  38.  *
  39.  * bzero --
  40.  *
  41.  *    Clear a block of memory to zeroes.  This routine is optimized
  42.  *    to do the clear in integer units, if the block is properly
  43.  *    aligned.
  44.  *
  45.  * Results:
  46.  *    Nothing is returned.  The memory at destPtr is cleared.
  47.  *
  48.  * Side effects:
  49.  *    None.
  50.  *
  51.  *----------------------------------------------------------------------
  52.  */
  53.  
  54. void
  55. bzero(destPtr, numBytes)
  56.     char *destPtr;            /* Where to zero. */
  57.     register int numBytes;        /* How many bytes to zero. */
  58. {
  59.     register int *dPtr = (int *) destPtr;
  60.  
  61. #ifdef VM_CHECK_BSTRING_ACCESS
  62.     Vm_CheckAccessible(destPtr, numBytes);
  63. #endif
  64.  
  65.     /*
  66.      * If the address is on an aligned boundary then zero as much
  67.      * as we can in big transfers (and also avoid loop overhead by
  68.      * storing many zeros per iteration).  Once we have less than
  69.      * a whole int to zero then it must be done by byte zeroes.
  70.      */
  71.  
  72.     if (((int) dPtr & WORDMASK) == 0) {
  73.     while (numBytes >= 16*sizeof(int)) {
  74.         dPtr[0] = 0;
  75.         dPtr[1] = 0;
  76.         dPtr[2] = 0;
  77.         dPtr[3] = 0;
  78.         dPtr[4] = 0;
  79.         dPtr[5] = 0;
  80.         dPtr[6] = 0;
  81.         dPtr[7] = 0;
  82.         dPtr[8] = 0;
  83.         dPtr[9] = 0;
  84.         dPtr[10] = 0;
  85.         dPtr[11] = 0;
  86.         dPtr[12] = 0;
  87.         dPtr[13] = 0;
  88.         dPtr[14] = 0;
  89.         dPtr[15] = 0;
  90.         dPtr += 16;
  91.         numBytes -= 16*sizeof(int);
  92.     }
  93.     while (numBytes >= sizeof(int)) {
  94.         *dPtr++ = 0;
  95.         numBytes -= sizeof(int);
  96.     }
  97.     if (numBytes == 0) {
  98.         return;
  99.     }
  100.     destPtr = (char *) dPtr;
  101.     }
  102.  
  103.     /*
  104.      * Zero the remaining bytes
  105.      */
  106.  
  107.     while (numBytes > 0) {
  108.     *destPtr++ = 0;
  109.     numBytes--;
  110.     }
  111. }
  112.